package dk.ucn.houseenabler;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class InformationActivity extends Activity {

	private Button saveNameButton;
	private EditText subjectNameTxtField;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_information);
        subjectNameTxtField = (EditText)findViewById(R.id.edittext_subjectname);
        
        saveNameButton = (Button)findViewById(R.id.btn_save_name);
        saveNameButton.setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				if(subjectNameTxtField.getText().toString() == null || subjectNameTxtField.getText().toString().equals("") || subjectNameTxtField.getText().toString().length() > 25 || subjectNameTxtField.getText().toString().length()<0)
				{
					Toast.makeText(getApplicationContext(), "Error in input, check your typing", Toast.LENGTH_SHORT).show();
					
				}else{
					Toast.makeText(getApplicationContext(), "Name Saved!", Toast.LENGTH_SHORT).show();
					switchTabInActivity(1, subjectNameTxtField.getText().toString());
				}
				
				
			}
		});
    }
    
    public void switchTabInActivity(int indexTabToSwitchTo, String subjectName){
    	MainActivity.setSubjectName(subjectName);        
        MainActivity.changeTabWithName(indexTabToSwitchTo, subjectName );
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_information, menu);
        return true;
    }
}
